package com.naihe.anderson.sms.broadcastReceiver;

import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;

import com.naihe.anderson.sms.application.NhSmsApp;
import com.naihe.anderson.sms.entity.SignatureMsg;
import com.naihe.anderson.sms.util.FileUtil;

public class SignatureMsgSendReceiver extends BroadcastReceiver {

	NhSmsApp nhSmsApp;
	public static final String SIGNATURE_SEND_RECEIVER_ACTION = "com.naihe.anderson.sms.broadcastReceiver.SEND";
	
	@Override
	public void onReceive(Context context, Intent intent) {
		nhSmsApp = ((NhSmsApp)context.getApplicationContext());
		long id = intent.getLongExtra("signatureMsgId", -1);
		FileUtil.addLog("SignatureMsgSendReceiver::onReceive() signatureMsgId=" + id, SignatureMsgSendReceiver.class, "SignatureMsgMgr", null);
		if(id == -1) return;
		
		SignatureMsg msg = nhSmsApp.getSignatureMsgMgr().getSignatureMsgInfoById(id);
		if(msg == null) return;
		
		nhSmsApp.getNhSmsMgr().sendSmsBySignatureMsg(msg);
		msg.setSignatureMsgStatut(SignatureMsg.SIGNATUREMSG_STATUT_SEND);
		nhSmsApp.getSignatureMsgMgr().updateSignatureMsgInfo(msg, false);
	}

}
